package com.comm.controller;

import com.comm.entity.vo.MessageModel;
import com.comm.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/login")

public class UserServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uname= request.getParameter("uname");
        String upwd= request.getParameter("upwd");
        MessageModel messageModel = userService.userLogin(uname,upwd);

        if(messageModel.getCode()==1) {
            request.getSession().setAttribute("user",messageModel.getObject());
            response.sendRedirect("/web/mainpage.jsp");
        }else{
            request.setAttribute("messageModel",messageModel);
            request.getRequestDispatcher("login.jsp").forward(request,response)  ;
        }
    }
}
